package 试题和试卷;

import GUI.questionWindow;
import 数据库和网络.myDatebase;
import GUI.browzeDefinitionWindow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class definitionQuestionBaseItem extends questionBaseItem{


    public definitionQuestionBaseItem(){}

    public definitionQuestionBaseItem(int n,question currentquestion){
        super(n,currentquestion);
        detailButton.addActionListener(new detailListener());
        doButton.addActionListener(new deleteListener());

    }
    public class deleteListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="delete  from questioncollection.definition_question where questionTitle='"+currentquestion.getTitle()+"'";
            try {
                questionbase.statement.execute(sql);

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            questionWindow.mainPanel.removeAll();
            questionWindow.mainPanel.updateUI();
        }

}

    public class detailListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="select * from questioncollection.definition_question where questionTitle='"+currentquestion.getTitle()+"'";
            try {
                questionbase.statement.execute(sql);
                questionbase.resultSet=questionbase.statement.executeQuery(sql);
                while (questionbase.resultSet.next()){
                    currentquestion.setText(questionbase.resultSet.getString("questiontext"));
                    currentquestion.setDifficulty(questionbase.resultSet.getDouble("questionDifficulties"));
                    currentquestion.setFullScore(questionbase.resultSet.getInt("fullScore"));
                    currentquestion.setRightOption(questionbase.resultSet.getString("right"));
                    currentquestion.setWrongOption(questionbase.resultSet.getString("wrong"));
                    currentquestion.setAnswer(questionbase.resultSet.getString("answer"));
                }

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            browzeDefinitionWindow definitionWindow=new browzeDefinitionWindow(currentquestion);
            definitionWindow.questionContent.setText(currentquestion.getText());
            definitionWindow.answer.setText(currentquestion.getAnswer());
            definitionWindow.title.setText(currentquestion.getTitle());
            definitionWindow.difficulty.setText(""+currentquestion.getDifficulty());
            definitionWindow.score.setText(""+currentquestion.getFullScore());
            definitionWindow.rightContent.setText(currentquestion.getRightOption());
            definitionWindow.wrongContent.setText(currentquestion.getWrongOption());
            definitionWindow.mainPanel.updateUI();

        }
    }
}
